<template>
  <div id="recList">
    <el-input size="mini" @keyup.enter.native="searchHandle" style="width: 300px" v-model="keywords" placeholder="搜索企业或工作名称"></el-input>
    <el-button @click="searchHandle()" style="margin-left: 10px" type="primary" size="mini">搜索</el-button>
    <el-table
        height="600"
        :data="recList"
        style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="岗位分类">
              <span>{{ props.row.workKind }}</span>
            </el-form-item>
            <el-form-item label="岗位薪资">
              <span>{{ props.row.salary }}</span>
            </el-form-item>
            <el-form-item label="经验要求">
              <span>{{ props.row.experience }}</span>
            </el-form-item>
            <el-form-item label="岗位地址">
              <span>{{ props.row.address }}</span>
            </el-form-item>
            <el-form-item label="岗位福利">
              <span>{{ props.row.treatment }}</span>
            </el-form-item>
            <el-form-item label="学历要求">
              <span>{{ props.row.degree }}</span>
            </el-form-item>
            <el-form-item label="技能要求">

                <li v-for="item in props.row.skills" :key="item">
                  {{item.skillExplain}}
                </li>

            </el-form-item>
            <el-form-item label="岗位职责">

              <li v-for="item in props.row.duties" :key="item">
                {{item.dutyExplain}}
              </li>

            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column
          label="岗位ID"
          prop="id">
      </el-table-column>
      <el-table-column
          label="岗位名称"
      >
        <template slot-scope="scope">
          {{scope.row.workName||'未填写'}}
        </template>
      </el-table-column>
      <el-table-column
          label="发布企业"
          prop="companyName">
      </el-table-column>
      <el-table-column
          label="更新时间">
        <template slot-scope="scope">
          {{scope.row.updateDate|formatDate}}
        </template>
      </el-table-column>
      <el-table-column
          label="状态">
        <template slot-scope="scope">
          {{scope.row.state?'已发布':'未发布'}}
        </template>
      </el-table-column>
      <el-table-column
          label="操作">
        <template slot-scope="scope">
         <el-button @click="releaseHandle(scope.row.id)" size="mini" type="success">{{scope.row.state?'下架':'发布'}}</el-button>
         <el-button @click="deleteHandle(scope.row.id)" size="mini" type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {delRec, getRecList, releaseSwitch} from "@/network/admin";

export default {
  name: "recList",
  data(){
    return{
      recList:[],
      keywords:''
    }
  },
  created() {
    this.init()
  },
  methods:{
    init(){
      getRecList(this.keywords).then(res=>{
        console.log(res)
        this.recList=res.data.extend.recruitmentList
      })
    },
    searchHandle(){
      this.init()
    },
    deleteHandle(id){
      delRec(id).then(res=>{
        this.$message.success(res.data.msg)
        this.init()
      })
    },
    releaseHandle(id){
      releaseSwitch(id).then(res=>{
        this.$message.success(res.data.msg)
        this.init()
      })
    }
  }
}
</script>

<style lang="stylus" scoped>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
